#ifndef frame_mdi_h__
#define frame_mdi_h__

#include "basic_window.hpp"

namespace winboost {
   namespace windows {

class frame_mdi : public basic_window
{
   typedef boost::shared_ptr<HWND__>   client_handle_type;
   HWND get_active(void) const;

   void tile_vertical(void);
   void tile_horizontal(void);
   void cascade(void);
   void arrange(void);
   void close_all(void);

public:
   frame_mdi(void);

   virtual HWND get_client_handle(void) const { return m_client.get(); }

private:
   client_handle_type m_client;

   LRESULT on_create(const winboost::events::message& e);
};

//-------------------------------------
// implementation
//-------------------------------------
inline frame_mdi::frame_mdi(void)
{
   set_message_handler(WM_CREATE, boost::bind(&frame_mdi::on_create, this, _1));
}

inline LRESULT frame_mdi::on_create(const winboost::events::message& e)
{
   CLIENTCREATESTRUCT clientcreate = {0};
   HINSTANCE hinst = instance_handle();

   HWND hwnd = ::CreateWindow(_T("MDICLIENT"), NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
      0, 0, 0, 0, handle(), (HMENU)1, hinst, (LPSTR)&clientcreate);

   assert(hwnd);

   m_client = client_handle_type(hwnd, resources::deleter_window());
   _the_module.m_hmdiclient = hwnd;
  
   return 0;
}

inline HWND frame_mdi::get_active(void) const
{
   HWND hwnd = (HWND)::SendMessage(get_client_handle(), WM_MDIGETACTIVE, 0, 0);
   return hwnd;
}

inline void frame_mdi::tile_vertical(void)
{
   assert(get_client_handle());
   ::SendMessage (get_client_handle(), WM_MDITILE, MDITILE_VERTICAL|MDITILE_SKIPDISABLED, 0);
}

inline void frame_mdi::tile_horizontal(void)
{
   assert(get_client_handle());
   ::SendMessage (get_client_handle(), WM_MDITILE, MDITILE_HORIZONTAL|MDITILE_SKIPDISABLED, 0);
}

inline void frame_mdi::cascade(void)
{
   assert(get_client_handle());
   ::SendMessage (get_client_handle(), WM_MDICASCADE, 0, 0);
}

inline void frame_mdi::arrange(void)
{
   assert(get_client_handle());
   ::SendMessage (get_client_handle(), WM_MDIICONARRANGE, 0, 0);
}

inline void frame_mdi::close_all(void)
{
}

   }
}

#endif // frame_mdi_h__


